﻿using Common;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ActivationGenerator
{
    public partial class Generator : Form
    {
        public Generator()
        {
            InitializeComponent();
        }

        private void cancelButton_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void generateButton_Click(object sender, EventArgs e)
        {
            long serial = Convert.ToInt64(productNumberTextBox.Text);
            long code = GuardManager.GenerateActivationCode(serial);
            activationCodeTextBox.Text = code.ToString();
        }

        private void Generator_Load(object sender, EventArgs e)
        {
            long serial = GuardManager.GetSerialNumber();
            productNumberTextBox.Text = serial.ToString();
        }

        private void productNumberTextBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = !char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar);
        }

        private void activationCodeTextBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = !char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar);
        }
    }
}
